package com.yloveg.controller;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import com.yloveg.base.BaseController;
import com.yloveg.common.PageUtil;
import com.yloveg.entity.ProductContent;
import com.yloveg.entity.ShopInfo;
import com.yloveg.service.ProductContentService;
import com.yloveg.service.ShopInfoService;

@Controller
@RequestMapping("/free")
public class FreeMainController extends BaseController {
    private final Logger logger = Logger.getLogger(this.getClass());

    @Autowired
    private ProductContentService productContentService;
    
    @Autowired
    private ShopInfoService shopInfoService;
    
    
    @RequestMapping({"{shopId}/index"}) 
    public String index(Integer pageNo,ProductContent product,ModelMap map){
    	String style = "0";
    	if(pageNo==null){
    		pageNo=1;
    	}
    	product.setPublisherState("1");
    	map = PageUtil.freemarkPage(map,productContentService.queryProductContentPage(pageNo,12,product));
    	map.put("productName", product.getProductName());
        //店铺信息
    	ShopInfo info = new ShopInfo();	
    	info.setId(product.getShopId());
    	info = shopInfoService.queryOneShopInfo(info);
    	if(info==null){
    		info = new ShopInfo();	
    	}
    	style = info.getShopStyle();
    	setSessionShop(info);
    	map.put("shopInfo", info);
        return "shopShow/view"+style+"/index";
    }
    
    @RequestMapping({"productDetial"}) 
    public String productDetial(Integer id,ModelMap map){
    	String style = "0";
    	if(id!=null){
        	ProductContent product = productContentService.selectByPrimaryKey(Long.valueOf(id));  
        	map.put("product", product);
        	ShopInfo info = new ShopInfo();
        	map.put("info", info);
        	info.setId(product.getShopId());
        	info = shopInfoService.queryOneShopInfo(info);
        	map.put("shopInfo", info);
        	style = info.getShopStyle();
    	}else{
    		map.put("product", new ProductContent());
    		map.put("shopInfo", new ShopInfo());
    	}
    	
        return "shopShow/view"+style+"/productDetial";
    }
    
    /****************************商业端登录后台日后要移到登录目录*************************************************/
    @RequestMapping({"my"}) 
    public String my(ModelMap map){
    	return "landing/mobile/personalCenter/my";
    }

}
